<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
			function dianWo(){
					var num = document.getElementById("num").value;
					var result = 1;
					var spanResult = document.getElementById("result");
					if (num<0) {
						alert("负数没有阶乘");
					} else if(num==0 || num == 1){
						result = 1;
						spanResult.innerHTML = result;
					} else {
						for (var i=num;i>=1;i--) {
							result *=i;
						}
						spanResult.innerHTML = result;
					}
				}
		</script>
	</head>
	<body>
		<div>
			<input type="text" id="num">
			<input type="button" value="阶乘" onclick="dianWo()">
			<span id="result"></span>
		</div>
	</body>
</html>
